package com.lixin.smartclassroom

import android.app.Activity
import android.content.Context
import android.os.Build
import android.os.StrictMode
import com.drake.brv.PageRefreshLayout
import com.drake.statelayout.StateConfig
import com.lixin.smartclassroom.app.App
import com.lixin.smartclassroom.utils.LoginManager
import com.lixinkeji.base.BaseApplication
import com.lixinkeji.base.RxManager
import com.lixinkeji.extension.get
import com.lixinkeji.extension.toast
import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.ClassicsHeader
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import com.simple.spiderman.SpiderMan
import com.tianma.netdetector.lib.NetStateChangeReceiver
import io.reactivex.functions.Consumer

/**
 * Description
 * Author: lwc
 * Date:2023/11/1 14:46
 */
class SmartClassroomApp : BaseApplication() {

    companion object {
        private lateinit var outInstants: SmartClassroomApp
        fun getInstants() = outInstants

        lateinit var instance: SmartClassroomApp
            private set
    }

    override fun onCreate() {
        super.onCreate()
        // 注册BroadcastReceiver
        NetStateChangeReceiver.registerReceiver(this);
        instance = this
        outInstants = this

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            var builder = StrictMode.VmPolicy.Builder()
            StrictMode.setVmPolicy(builder.build())
            builder.detectFileUriExposure();
        }


        StateConfig.apply {
            emptyLayout = R.layout.layout_empty

//            setRetryIds(R.id.msg) // 全局的重试Id

            onLoading {

            }

            onEmpty {

            }

            onError {

            }
        }



        SmartRefreshLayout.setDefaultRefreshHeaderCreator { context, layout ->
            ClassicsHeader(
                context
            )
        }

        SmartRefreshLayout.setDefaultRefreshFooterCreator { context, layout ->
            ClassicsFooter(
                context
            )
        }


        PageRefreshLayout.startIndex = 1 // startIndex即index变量的初始值
        App.init(this)
        val isLogin =
            getSharedPreferences("config", Context.MODE_PRIVATE).get<Boolean>("isLogin", false);
        if (isLogin!!) {

            App.initSdk()
        }
    }

    override fun onTerminate() {
        super.onTerminate()
        // 取消BroadcastReceiver注册
        NetStateChangeReceiver.unregisterReceiver(this);
    }


}